﻿using System;
using Caliburn.Micro;

namespace Zero.Frontend
{
    /// <summary>
    /// Default messagebox, that uses standard windows messageboxes.
    /// </summary>
    public class DefaultMessageBoxService : IMessageBoxService
    {
        private static System.Windows.MessageBoxButton ConvertButton(MessageBoxButton button)
        {
            switch (button)
            {
                case MessageBoxButton.OK:
                    return System.Windows.MessageBoxButton.OK;
                case MessageBoxButton.OKCancel:
                    return System.Windows.MessageBoxButton.OKCancel;
                case MessageBoxButton.YesNo:
                    return System.Windows.MessageBoxButton.YesNo;
                case MessageBoxButton.YesNoCancel:
                    return System.Windows.MessageBoxButton.YesNoCancel;
                default:
                    throw new ArgumentOutOfRangeException("button");
            }
        }

        private static MessageBoxResult ConvertResult(System.Windows.MessageBoxResult result)
        {
            switch (result)
            {
                case System.Windows.MessageBoxResult.None:
                    return MessageBoxResult.None;
                case System.Windows.MessageBoxResult.OK:
                    return MessageBoxResult.OK;
                case System.Windows.MessageBoxResult.Cancel:
                    return MessageBoxResult.Cancel;
                case System.Windows.MessageBoxResult.Yes:
                    return MessageBoxResult.Yes;
                case System.Windows.MessageBoxResult.No:
                    return MessageBoxResult.No;
                default:
                    throw new ArgumentOutOfRangeException("result");
            }
        }

        MessageBoxResult IMessageBoxService.Show(string message, string caption, MessageBoxButton buttons)
        {
            var result = System.Windows.MessageBox.Show(message, caption, ConvertButton(buttons));
            return ConvertResult(result);
        }
    }
}
